package com.nondo.rdp.finance.repository.activity;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.finance.domain.activity.MarketRecord;

public interface MarketRecordRepository extends JpaRepository<MarketRecord, Long>, JpaSpecificationExecutor<MarketRecord> {
    @Query("select a from MarketRecord a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<MarketRecord> findOne(@Param("id") int id);

    @Modifying
    @Query("update MarketRecord set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    MarketRecord save(MarketRecord marketRecord);

    @Query("select a from MarketRecord a where a.user.id=? and a.type=? and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	MarketRecord getOne(Long uid, int type);

}
